package com.hp.gxw.utils;

import com.alibaba.fastjson.JSONObject;
import com.hp.gxw.entity.SysUser;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Component;

@Component
public class ShiroUtil {

	/**
     * 获取当前登录用户对象
     * @return {SysUser}
     */
    public static SysUser getUser() {
		String userStr = JSONObject.toJSONString(SecurityUtils.getSubject().getPrincipal());
		SysUser user = BeanUtil.parseObjToBean(userStr, SysUser.class);
        return user;
    }
    
    /**
     * 获取当前登录用户id
     * @return {String}
     */
    public static Long getUserId() {
        return getUser().getId();
    }


	public static String getUserName() {
		return getUser().getUserName();
	}

}
